package models

import (
	"time"

	"gorm.io/gorm"
)

// MaSaleInfoLogDetail [...]
type MaSaleInfoLogDetail struct {
	ID              int       `gorm:"autoIncrement:true;primaryKey;column:id;type:bigint;not null" json:"id" json_old:"ID"`
	SalesID         string    `gorm:"index:idx_salesid_goodsid,priority:1,type:btree;column:sales_id;type:varchar(127);not null" json:"sales_id" json_old:"SalesID"`
	GoodsID         string    `gorm:"index:idx_salesid_goodsid,priority:2,type:btree;column:goods_id;type:bigint;not null;default:0;comment:商品ID" json:"goods_id" json_old:"GoodsID"`
	GoodsName       string    `gorm:"column:goods_name;type:varchar(125);not null;comment:商品名称" json:"goods_name" json_old:"GoodsName"`
	PreNum          int       `gorm:"primaryKey;column:pre_num;type:int;not null;default:0;comment:操作前数量" json:"pre_num" json_old:"PreNum"`
	LastNum         int       `gorm:"column:last_num;type:int;not null;default:0;comment:操作后数量" json:"last_num" json_old:"LastNum"`
	ChangeNum       int       `gorm:"column:change_num;type:int;not null;default:0;comment:变动后数量" json:"change_num" json_old:"ChangeNum"`
	AddTime         time.Time `gorm:"column:add_time;type:datetime;default:null" json:"-" json_old:"-"`
	AddTimeFormated string    `gorm:"-"  json:"add_time" json_old:"AddTime"`
	LogID           int64     `gorm:"column:log_id;type:bigint;default:null" json:"log_id" json_old:"LogID"`
	CreatedAt       int64     `gorm:"column:created_at;autoCreateTime;type:int;size:64;comment:创建时间" json:"created_at"`
}

func (m *MaSaleInfoLogDetail) AfterFind(tx *gorm.DB) (err error) {
	if !m.AddTime.IsZero() {
		AddTimeByte, _ := DateTime(m.AddTime).MarshalDateTime()
		m.AddTimeFormated = string(AddTimeByte)
	}
	return
}

// TableName get sql table name.获取数据库表名
func (m MaSaleInfoLogDetail) TableName() string {
	return "ma_sale_info_log_detail"
}

// 模式自动注册
func init() {
	Models = append(Models, &MaSaleInfoLogDetail{})
}
